$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'oa/userconfig/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '', name: 'merchantId', index: 'merchant_id', width: 80 }, 			
			{ label: '第三方用户唯一凭证', name: 'wxAppid', index: 'wx_appid', width: 80 }, 			
			{ label: '第三方用户唯一凭证密钥，即appsecret', name: 'wxSecret', index: 'wx_secret', width: 80 }, 			
			{ label: 'Token', name: 'wxToken', index: 'wx_token', width: 80 }, 			
			{ label: '应用的key,唯一标识', name: 'dingAppkey', index: 'ding_appkey', width: 80 }, 			
			{ label: '应用的密钥', name: 'dingAppsecret', index: 'ding_appsecret', width: 80 }, 			
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

 

$.get(baseURL + "oa/userconfig/infoconfig", function(r){
	var vm = new Vue({
		el:'#rrapp',
		data:{
			showList: false,
			title: null,
			userConfig: r.userConfig
		},
		methods: {
			query: function () {
				vm.reload();
			},
			add: function(){
				vm.showList = false;
				vm.title = "新增";
				vm.userConfig = {};
			},
			update: function (event) {
				var id = getSelectedRow();
				if(id == null){
					return ;
				}
				vm.showList = false;
	            vm.title = "修改";
	            
	            vm.getInfo(id)
			},
			saveOrUpdate: function (event) {
				var url = vm.userConfig.id == null ? "oa/userconfig/save" : "oa/userconfig/update";
				$.ajax({
					type: "POST",
				    url: baseURL + url,
	                contentType: "application/json",
				    data: JSON.stringify(vm.userConfig),
				    success: function(r){
				    	if(r.code === 0){
							alert('操作成功', function(index){
								vm.reload();
							});
						}else{
							alert(r.msg);
						}
					}
				});
			},
			del: function (event) {
				var ids = getSelectedRows();
				if(ids == null){
					return ;
				}
				
				confirm('确定要删除选中的记录？', function(){
					$.ajax({
						type: "POST",
					    url: baseURL + "oa/userconfig/delete",
	                    contentType: "application/json",
					    data: JSON.stringify(ids),
					    success: function(r){
							if(r.code == 0){
								alert('操作成功', function(index){
									$("#jqGrid").trigger("reloadGrid");
								});
							}else{
								alert(r.msg);
							}
						}
					});
				});
			},
			getInfo: function(id){
				$.get(baseURL + "oa/userconfig/info/"+id, function(r){
	                vm.userConfig = r.userConfig;
	            });
			},
			getInfoConfig: function(){
				$.get(baseURL + "oa/userconfig/infoconfig", function(r){
	                vm.userConfig = r.userConfig;
	            });
			},
			reload: function (event) {
				vm.showList = false;
				var page = $("#jqGrid").jqGrid('getGridParam','page');
				$("#jqGrid").jqGrid('setGridParam',{ 
	                page:page
	            }).trigger("reloadGrid");
			}
		},
		created: function () {
			console.log('根组件：beforeMount');
			this.title = "全局配置";
			//this.userConfig = this.getInfoConfig();
		    console.log('根组件：created');
		}
	});
});

